﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoVuaClient
{
    class QuanTot : QuanCo
    {
        private bool _chuaXuatQuan;
        public QuanTot(bool pheMinh)
        {
            PheMinh = pheMinh;
            TenQuanCo = "Tot";
            ChuaXuatQuan = true;
            if (PheMinh)
            {
                PathImage = @"/CoVuaClient;component/Pic/PawnYellow.png";
            }
            else
            {
                PathImage = @"/CoVuaClient;component/Pic/PawnBlack.png";
            }
        }

        public bool ChuaXuatQuan
        {
            get { return _chuaXuatQuan; }
            set { _chuaXuatQuan = value; }
        }
        public override List<OCo> NhungOCoTheDi(BanCo banCo, OCo oHienTai, bool kiemTraChieuTuong)
        {
            List<OCo> danhSach = new List<OCo>();
            if (!kiemTraChieuTuong)
            {
                if (oHienTai.Dong == 1)
                {
                    return danhSach;
                }
                OCo oKeTiep = new OCo(char.Parse(oHienTai.Cot), oHienTai.Dong - 1);
                if (!KiemTraCoQuanTa(banCo, oKeTiep))
                {
                    danhSach.Add(oKeTiep);
                }

                if (oHienTai.Cot != "H" && oHienTai.Cot != "A")
                {
                    OCo oCheoPhai;
                    oCheoPhai = new OCo(oHienTai.CotKeTiep(), oHienTai.Dong - 1);
                    if (KiemTraCoQuanDich(banCo, oCheoPhai))
                    {
                        danhSach.Add(oCheoPhai);
                    }
                    OCo oCheoTrai;
                    oCheoTrai = new OCo(oHienTai.CotTruoc(), oHienTai.Dong - 1);
                    if (KiemTraCoQuanDich(banCo, oCheoTrai))
                    {
                        danhSach.Add(oCheoTrai);
                    }
                }
                else
                {
                    if (oHienTai.Cot == "H")
                    {
                        OCo oCheoTrai;
                        oCheoTrai = new OCo(oHienTai.CotTruoc(), oHienTai.Dong - 1);
                        if (KiemTraCoQuanDich(banCo, oCheoTrai))
                        {
                            danhSach.Add(oCheoTrai);
                        }
                    }
                    else
                    {
                        OCo oCheoPhai;
                        oCheoPhai = new OCo(oHienTai.CotKeTiep(), oHienTai.Dong - 1);
                        if (KiemTraCoQuanDich(banCo, oCheoPhai))
                        {
                            danhSach.Add(oCheoPhai);
                        }
                    }
                }




                if (ChuaXuatQuan)
                {
                    OCo oCach2Buoc;
                    oCach2Buoc = new OCo(char.Parse(oHienTai.Cot), oHienTai.Dong - 2);
                    if (!KiemTraCoQuanTa(banCo, oCach2Buoc))
                    {
                        danhSach.Add(oCach2Buoc);
                    }
                }
            }
            else
            {
                if (oHienTai.Dong == 8)
                {
                    return danhSach;
                }
                OCo oKeTiep = new OCo(char.Parse(oHienTai.Cot), oHienTai.Dong + 1);
                if (!KiemTraCoQuanTa(banCo, oKeTiep))
                {
                    danhSach.Add(oKeTiep);
                }

                if (oHienTai.Cot != "H" && oHienTai.Cot != "A")
                {
                    OCo oCheoPhai;
                    oCheoPhai = new OCo(oHienTai.CotKeTiep(), oHienTai.Dong + 1);
                    if (KiemTraCoQuanTa(banCo, oCheoPhai))
                    {
                        danhSach.Add(oCheoPhai);
                    }
                    OCo oCheoTrai;
                    oCheoTrai = new OCo(oHienTai.CotTruoc(), oHienTai.Dong + 1);
                    if (KiemTraCoQuanTa(banCo, oCheoTrai))
                    {
                        danhSach.Add(oCheoTrai);
                    }
                }
                else
                {
                    if (oHienTai.Cot == "H")
                    {
                        OCo oCheoTrai;
                        oCheoTrai = new OCo(oHienTai.CotKeTiep(), oHienTai.Dong + 1);
                        if (KiemTraCoQuanTa(banCo, oCheoTrai))
                        {
                            danhSach.Add(oCheoTrai);
                        }
                    }
                    else
                    {
                        OCo oCheoPhai;
                        oCheoPhai = new OCo(oHienTai.CotTruoc(), oHienTai.Dong + 1);
                        if (KiemTraCoQuanTa(banCo, oCheoPhai))
                        {
                            danhSach.Add(oCheoPhai);
                        }
                    }
                }

                if (ChuaXuatQuan)
                {
                    OCo oCach2Buoc;
                    oCach2Buoc = new OCo(char.Parse(oHienTai.Cot), oHienTai.Dong + 2);
                    if (!KiemTraCoQuanDich(banCo, oCach2Buoc))
                    {
                        danhSach.Add(oCach2Buoc);
                    }
                }
            }
            
            return danhSach;
        }
        public override void ChangeState()
        {
            DangChon = !DangChon;
            if (DangChon)
            {
                PathImage = @"/CoVuaClient;component/Pic/PawnYellowChecked.png";
            }
            else
            {
                PathImage = @"/CoVuaClient;component/Pic/PawnYellow.png";
            }
        }
        public override void DaXuatQuan()
        {
            ChuaXuatQuan = false;
        }
    }
}
